home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / asm / alib11b.zip / CODE1.ZIP / DISPINFO / DISPINFO.ASM
Assembly Source File  |  1994-10-06  |  9KB  |  391 lines

  1.     page    66,132
  2. comment 
  3. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( SYSTEM  )
  4. CHECK_ANSI - check if ANSI active
  5. ;
  6. ; inputs:    none
  7. ; output:    CF = 1 if no ANSI driver active
  8. ;            CF = 0 if ANSI active
  9. ;* * * * * * * * * * * * * *
  10. 
  11.     public    CHECK_ANSI
  12. CHECK_ANSI        PROC    FAR
  13.      APUSH   AX,DX,DS
  14.      MOV     AX,CS
  15.      MOV     DS,AX
  16.      CALL    console_input
  17.      CALL    CHECK_ANSI_cont1
  18.  
  19.      DB         1BH,'[6n$'
  20. ;
  21. CHECK_ANSI_cont1:
  22.      POP     DX
  23.      CALL    console_output
  24.      MOV     AH,0Bh        ;check STDIN status, al=ff if input
  25.      INT     21h
  26.      CMP     AL,0FFh
  27.      JZ      IA_1        ;jmp if char. is ready from ansi call
  28.      CALL    isansi_cont2
  29.  
  30.      db         0dH,'    ',0dH,'$'
  31.  
  32. isansi_cont2:
  33.      POP    DX
  34.      CALL    console_output
  35.      STC
  36.      JMP     IA_2
  37. IA_1:
  38.      CALL    console_input
  39.      CLC
  40. IA_2:
  41.      APOP    DS,DX,AX
  42.      JB      NO_ANSI
  43.      CLC
  44.      RETF
  45. NO_ANSI:
  46.      STC
  47.      RETF
  48. CHECK_ANSI    ENDP
  49. ;------------------------------
  50. console_output:
  51.      MOV     AH,09
  52.      INT     21h
  53.      RET
  54.  
  55. console_input:
  56.      MOV     AH,06
  57.      MOV     DL,0FFh
  58.      INT     21h
  59.      JNZ     console_input
  60.      RET
  61.  
  62. comment 
  63. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( SYSTEM  )
  64. DISPLAY_INFO - determine display information
  65. ;
  66. ; inputs:    none
  67. ;            
  68. ; output:    AL = screen rows
  69. ;            CH = screen columns
  70. ;            BX:[SI] = video buffer address
  71. ;            register DX is modified
  72. ;* * * * * * * * * * * * * *
  73. 
  74.     public    display_info
  75. display_info:
  76.     push    es
  77.     call    detectvid            ;get video type
  78.     cmp    ax,0
  79.     je    display_info_exit        ;exit if no display
  80. ;
  81. ; check for special case, dual display and alternate monochrome active
  82. ;
  83.     mov    bx,0
  84.     mov    es,bx
  85.     cmp    al,3                ;check if color display
  86.     jb    mono_port            ;jmp if mono
  87.     cmp    word ptr es:[463h],3d4h        ;verify color port active
  88.     je    port_ck_end            ;jmp if port ok
  89.     mov    ax,2                ;force monochrome display
  90.     jmp    port_ck_end
  91. mono_port:
  92.     cmp    word ptr es:[463h],3b4h        ;verify mono port active
  93.     je    port_ck_end
  94.     mov    ax,5                ;force cga color
  95. port_ck_end:
  96.     
  97.     push    ax
  98.     mov    ax,0500h
  99.     int    10h                ;force page 0
  100.  
  101.     mov    ax,0
  102.     mov    es,ax
  103.     mov    bh,es:[449h]            ;get display mode
  104.     pop    ax
  105.  
  106.     cmp    al,6
  107.     jbe    get_rows            ;jmp if mono or cga
  108.     cmp    al,9
  109.     je    get_rows            ;jmp if cga compatable
  110.  
  111.     push    ax
  112.     push    bx
  113.     mov    ax,1130h
  114.     mov    bh,0
  115.     push    es
  116.     int    10h
  117.     pop    es
  118.     pop    bx
  119.     pop    ax
  120.     mov    bl,dl                ;move rows to -bl-
  121.     jmp    rows_ok      
  122.  
  123. get_rows:
  124.     mov    bl,es:[484h]            ;get rows
  125.     cmp    bl,0
  126.     je    fix_rows            ;jmp if row info bad
  127.     cmp    bl,80
  128.     jb    rows_ok                ;jmp if row info found
  129. fix_rows:
  130.     mov    bl,24                ;force 25 lines on screen
  131. rows_ok:
  132.     inc    bl
  133. get_columns:
  134.     mov    cx,word ptr es:[44ah]        ;get columns on display
  135. display_info_exit:
  136.     pop    es
  137.     ret    
  138. comment 
  139. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( SYSTEM  )
  140. DETECTVID -  determine display type
  141. ;
  142. ;  inputs: none
  143. ;  
  144. ;  outputs:  ax = 0  no display
  145. ;                 1  monochrome
  146. ;                 2  hercules 
  147. ;                 3  cga digital (mono)
  148. ;                 4  cga analog  (mono)
  149. ;                 5  cga analog (color)
  150. ;                 6  ega mono
  151. ;                 7  ega color 64k
  152. ;                 8  ega color 64k+
  153. ;                 9  cga compatable
  154. ;                10  vga mono
  155. ;                11  vga color 
  156. ;* * * * * * * * * * * * * *
  157. 
  158. vga_mono    equ    10
  159. vga_color    equ    11
  160. monochrome    equ    1
  161. hercules    equ    2
  162.  
  163.     public    detectvid
  164. detectvid:
  165.     mov ax,1a00h          ;used by mcga and vga
  166.     int 10h
  167.     cmp al,1ah            ;if al = 1ah then mcga or vga is present
  168.     jnz dt1
  169.     cmp bl,7              ;if active monitor is monochrome vga
  170.     jnz do1
  171.     mov ax,vga_mono       ;mono vga found
  172.     ret
  173. do1:
  174.     cmp bl,8              ;if active monitor is color vga
  175.     jnz do2
  176.     mov ax,vga_color      ;color vga found
  177.     ret
  178. do2:
  179.     cmp bl,0ah            ;if digital mcga
  180.     jnz do3
  181.     mov ax,3              ;digital mcga found
  182.     ret
  183. do3:
  184.     cmp bl,0bh            ;if monochrome mcga
  185.     jnz do4
  186.     mov ax,4              ;analog monochrome mcga found
  187.     ret
  188. do4:
  189.     cmp bl,0ch            ;if color mcga
  190.     jnz dt1
  191.     mov ax,5              ;analog color mcga found
  192.     ret
  193. dt1:
  194.     mov ah,12h            ;used by ega
  195.     mov bl,10h
  196.     int 10h
  197.     cmp bl,10h            ;if bl is not 10h then ega is present
  198.     jz dt2
  199.     cmp bh,1              ;if monochrome ega
  200.     jnz do5
  201.     mov ax,6              ;monochrome ega
  202.     ret
  203. do5:
  204.     or bl,bl              ;or 64k ega board
  205.     jnz do6
  206.     mov ax,7              ;color ega with 64k memory
  207.     ret
  208. do6:
  209.     mov ax,8              ;color ega with > 64k memory
  210.     ret
  211. dt2:
  212.     mov dx,3d4h           ;address for cga crtc
  213.     call find6845         ;look for controller
  214.     jnc dt3               ;if clear then cga present
  215.     mov dx,3b4h           ;address for hercules or mda
  216.     call find6845         ;look for controller
  217.     jnc dt4               ;jump if hercules or mda present
  218.     mov ax,0              ;unable to detect card
  219.     ret
  220. dt3:
  221.     mov ax,9              ;cga compatible present
  222.     ret
  223. dt4:
  224.     mov dl,0bah           ;read this port
  225.     in al,dx
  226.     and al,80h            ;get value in ah
  227.     mov ah,al
  228.     mov cx,8000h          ;loop this many times
  229. dt5:
  230.     in al,dx              ;read port
  231.     and al,80h
  232.     cmp ah,al             ;has value changed
  233.     loopz dt5
  234.     jcxz dt6              ;if cx = 0 then mda is present
  235.     mov ax,hercules       ;hercules card
  236.     ret
  237. dt6:
  238.     mov ax,monochrome     ;mda card
  239.     ret
  240. ;-------------------------------------------------------------------------
  241.     public    find6845
  242. find6845 proc near        ;find out if crtc is present
  243.     mov al,0fh            ;select reg ( cursor low )
  244.     out dx,al
  245.     inc dx
  246.     in al,dx              ;al = cursor low position
  247.     mov ah,al             ;save value in ah
  248.     mov al,66h            ;arbitrary value
  249.     out dx,al             ;write to crtc
  250.     mov cx,100h
  251. f61:
  252.     loop f61              ;wait for response
  253.     in al,dx
  254.     xchg ah,al            ;ah = returned value
  255.     out dx,al             ;reset port
  256.     cmp ah,66h            ;was value unchanged
  257.     je f62
  258.     stc                   ;if no response
  259. f62:
  260.     ret
  261. find6845 endp
  262.  
  263. comment 
  264. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( SYSTEM  )
  265. FIND_DISPLAY_SEGMENT  -  scan for current display buffer segment
  266. ;
  267. ;  inputs:   display mode 3 or 7 must be set and display page must = 0
  268. ;  
  269. ;  output:   display_segment is set
  270. ;
  271. ;* * * * * * * * * * * * * *
  272. 
  273.     public    find_display_segment
  274. find_display_segment:
  275.     push    ax
  276.     push    bx
  277.     push    es
  278.     cli
  279.     mov    ax,0b000h        ;display seg?
  280.     mov    es,ax
  281.     mov    bx,es:[0]        ;save current data
  282.     mov    word ptr es:[0],0101h    ;store code 0101 at b000
  283.     mov    ax,0b800h        ;move to b800
  284.     mov    es,ax
  285.     mov    cx,es:[0]        ;save current data
  286.     mov    word ptr es:[0],0303h    ;store code 0303 at b800
  287.  
  288.     push    bx
  289.     push    cx
  290.  
  291.     mov    ah,3
  292.     mov    bh,0
  293.     int    10h            ;read cursor position -> dx
  294.     mov    cx,dx            ;save cursor posn
  295.  
  296.     mov    ah,2            ;move
  297.     mov    bh,0            ; cursor
  298.     mov    dx,0            ;   to page 0
  299.     int    10h            ;     top left
  300.  
  301.     mov    ah,8            ;read
  302.     mov    bh,0            ;  data
  303.     int    10h            ;    at cursor
  304. ;
  305. ; restore cursor position
  306. ;
  307.     push    ax            ;save data read
  308.     mov    dx,cx
  309.     mov    ah,2
  310.     int    10h
  311.     pop    ax            ;restore data read 
  312. ;
  313. ; restore origional display buffer data
  314. ;
  315.     pop    cx            ;  origional
  316.     pop    bx            ;   display contents
  317.     push    ax            ;save data read
  318.     mov    ax,0b000h
  319.     mov    es,ax
  320.     mov    word ptr es:[0],bx
  321.     mov    ax,0b800h
  322.     mov    es,ax
  323.     mov    word ptr es:[0],cx
  324. ;
  325. ; recover data read from display to determine segment location
  326. ;    
  327.     pop    ax
  328.     cmp    ax,0101h
  329.     je    use_b000
  330. use_b800:
  331.     mov    ax,0b800h
  332.     jmp    set_seg_cont
  333. use_b000:
  334.     mov    ax,0b000h
  335. set_seg_cont:
  336.     mov    lib_info.crt_seg,ax
  337.     sti
  338.     pop    es
  339.     pop    bx
  340.     pop    ax
  341.     ret
  342.  
  343. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  344. ; set_display_flags - determine cga snow flag and mono flag default settings
  345. ;  inputs: crt_info data stored in data base
  346. ;  output: al = mono flag (1=mono)
  347. ;          dx = snow flag (cga port if cga)
  348. ;
  349. set_display_flags:
  350.     sub    ax,ax
  351.     mov    es,ax
  352. ;
  353. ; get display mode
  354. ;
  355.     mov    al,byte ptr es:[449h]    ;get display mode
  356.     mov    lib_info.crt_mode,al    
  357. ;
  358. ; force display page zero
  359. ;
  360.     mov    ah,5
  361.     mov    al,0            ;page 0
  362.     int    10h    
  363. ;
  364. ; set cga flag
  365. ;
  366.     mov    al,lib_info.crt_type
  367.     cmp    al,3
  368.     jb    mono_display
  369.     cmp    al,5
  370.     jbe    cga_display
  371.     cmp    al,9
  372.     je    cga_display
  373. ;
  374. ; we must have a color display, it is not a cga or mono
  375. ;
  376.     mov    al,0
  377.     mov    dx,0
  378.     jmp    sdf_exit    
  379. ;
  380. mono_display:
  381.     mov    al,1
  382.     mov    dx,0
  383.     jmp    sdf_exit
  384.     
  385. cga_display:
  386.     mov    al,0
  387.     mov    dx,3dah
  388. sdf_exit:
  389.     ret
  390.